package level02.two;

import level01.MyHandler;


import java.io.File;
import java.lang.reflect.Proxy;

public class Two {
    private static File file = new File("test_1.txt");
    public static void main(String[] args) throws Exception {

        BookDAO bookDAO = new BookDAO();

        //通过 Java 动态代理机制，为BookDAO对象创建一个代理对象
        BookDAOInterface instance = (BookDAOInterface) Proxy.newProxyInstance(
                //获取类加载器(将生成的代理类加载到内存)
                BookDAO.class.getClassLoader(),
                //对象实现的接口(代理对象要伪装成的接口类型)
                BookDAO.class.getInterfaces(),
                //代理逻辑处理器(代理在目标方法前后干的活)
                new MyProxy(bookDAO)
        );
        instance.message(file);

    }
}
